// Filename: FFT.H

/************   Fast Fourier Transform Header File *****************\

1993 (c) CDI UI, The USSR Academy of Sciences, Samara

\*******************************************************************/

#ifndef __FFT
#define __FFT

#include <complex.h>

const int  FFTDMAXSIZE  = 2048;
  // Maximum FFT array size for double precision.
const int  FFTFMAXSIZE  = 4096;
  // Maximum FFT array size for normal precision.
const long FFTHMAXSIZE  = 65536L;
  // Maxinum FFT array size for large arrays.
const long FFTDHMAXSIZE  = 32768L;
  // Maxinum FFT array size for large arrays (double precision).
const int  FFT2DMAXSIZE = 2048;
  // Maxinum 2-D FFT picture size.

struct Complex { float re, im; };
  // Data structure for fftf and fftfh functions.
struct Comp16 { double re, im; };

// class complex { ... defined in complex.h ... };
  // Data structure for fftd and fftfh functions.

const int  // FFT Errors
  NoError        = 0,
    // No errors encontered.
  InvalidSize    = 1,
    // Invalid FFT array size: less then 0,
    // greater then maximum, or not a power of 2.
  InvalidParams  = 2,
    // Not allowed value of parameter in function call.
  NoFile         = 3,   // Source picture file is absent.
  WrongType      = 4,   // Source picture of not allowed type.
  InvalidPicture = 5,
    // Source picture file has the wrong structure.
  NoDiskSpace    = 6,
    // Not enough disk space to allocate destination file(s).
  NoMemory       = 7,
    // Not enough core memory for inner buffers.
  InvalidPicSize = 8,   // Invalid picture file size (see InvalidSize).
  DifSizes       = 9,
    // Two source pictures have not identical sizes for _32to64.
  User_break     =10;
    // User has cancelled the procedure.

// 1-D Transforms

int fftd( complex *x, int Size, int DirInv );
int fftf( Complex *x, int Size, int DirInv );
int fftfs( Complex *x, int Size, int DirInv );
int ffth( complex huge *x, long Size, int DirInv );
int ffth( Complex huge *x, long Size, int DirInv );
//int fftdhts( Comp16 huge *x, unsigned int Size, int DirInv, Comp16 huge *tab);
int fftdhts( Comp16 huge *x, unsigned int Size, Comp16 huge *tab);
/* 
   x      -  FFT array (source and destination), 
   Size   -  array length,
   DirInv -  Flag of Direct (1) or inverse (-1) transform.
   tab    -  table of exponents.
*/   


// 2-D Transforms

int fft2co
  ( char *SrcComplexPic, char *DstComplexPic, int DirInv, 
    double Scale = 0, double Expand = 0 );
int fft2codht
  ( char *SrcComplexPic, char *DstComplexPic, int DirInv, 
    double Scale = 0, double Expand = 0 );
/* 
2-D FFT transform for complex data:
   SrcComplexPic  - Source picture file name;
   DstComplexPic  - Destination picture file name;
   DirInv         - Flag of Direct (1) or inverse (-1) transform;
   Scale          - Scaling factor;
     If Scale is zero then it is automatically calculated 
       for direct transform as equal to 1,
       for inverse transform as equal to 1/(HorSize*VerSize).
   Expand         - Percent of zeros to add to source picture.
   The source picture is expanded with zeros by Expand % and then 
     is expanded with zeros to the sizes of power of 2.
   Source (SrcComplexPic) and destination (DstComplexPic) pictures 
   are considered to be of type 64 (real and imag parts are of 
   type float).
*/   
    
int fft2re
  ( char *SrcPic,  char *ComplexPic, int DirInv, 
    double Scale = 0, double Expand = 0 );
int fft2redht
  ( char *SrcPic,  char *ComplexPic, int DirInv, 
    double Scale = 0, double Expand = 0 );
/* 
2-D FFT transform for real data:
   SrcPic      - Source picture file name;
   ComplexPic  - Destination picture file name;
   DirInv      - Flag of Direct (1) or inverse (-1) transform;
   Scale       - Scaling factor;
     If Scale is zero then it is automatically calculated 
       for direct transform as equal to 1,
       for inverse transform as equal to 1/(HorSize*VerSize).
   Expand      - Percent of zeros to add to source picture.
   The source picture is expanded with zeros by Expand % and then 
     is expanded with zeros to the sizes of power of 2.
   Source picture SrcPic is considered to be of type 32 (float) 
   and contains real data (considering that imag part is zero).
   Destination picture ComplexPic will be of type 64
     (real and imag parts are of type float).
*/   
    
int fft2ph
  ( char *SrcPic,  char *ComplexPic, int DirInv, 
    double Scale = 0, double Expand = 0 );
int fft2phdht
  ( char *SrcPic,  char *ComplexPic, int DirInv, 
    double Scale = 0, double Expand = 0 );
/* 
2-D FFT transform for real data:
   SrcPic      - Source picture file name;
   ComplexPic  - Destination picture file name;
   DirInv      - Flag of Direct (1) or inverse (-1) transform;
   Scale       - Scaling factor;
     If Scale is zero then it is automatically calculated 
       for direct transform as equal to 1,
       for inverse transform as equal to 1/(HorSize*VerSize).
   Expand      - Percent of zeros to add to source picture.
   The source picture is expanded with zeros by Expand % and then 
     is expanded with zeros to the sizes of power of 2.
   Source picture SrcPic is considered to be of type 32 (float) 
   and contains phase data (considering that module is 1).
   Destination picture ComplexPic will be of type 64
     (real and imag parts are of type float).
*/   

int fft2mp
  ( char *SrcModPic,  char *SrcPhPic,  char *ComplexResPic, 
    int DirInv, double Scale = 0, double Expand = 0);
int fft2mpdht
  ( char *SrcModPic, char *SrcPhPic, char *DstPic,
    int DirInv, double Scale = 0, double Expand = 0);
/* 
2-D FFT transform for module/phase data:
   SrcModPic      - Source picture file name (module);
   SrcPhPic       - Source picture file name (phase);
   ComplexResPic  - Destination picture file name;
   DirInv         - Flag of Direct (1) or inverse (-1) transform;
   Scale          - Scaling factor;
     If Scale is zero then it is automatically calculated 
       for direct transform as equal to 1,
       for inverse transform as equal to 1/(HorSize*VerSize).
   Expand         - Percent of zeros to add to source picture.
   The source picture is expanded with zeros by Expand % and then 
     is expanded with zeros to the sizes of power of 2.
   Source pictures SrcModPic, SrcPhPic are considered to be 
   of type 32 (float) and contain module and phase data.
   The result picture ComplexResPic will be of type 64
     (real and imag parts are of type float).
*/   

// Complex data conversions

const  // Conversion Modes
  Real_Imag  = 1,    
    // Float pictures contain real and imag part of complex data.
  Mod_Arg    = 2;
    // Float pictures contain module and argument of complex data.


int _64to32( char *ComplexPic, char *Dst1Pic, char *Dst2Pic, int Mode );
/* 
Transforming of complex data to real data:
   ComplexPic  - Source picture file name;
   Dst1Pic     - First destination picture file name;
   Dst2Pic     - Second destination picture file name;
   Mode        - Flag of transform method;
     Source picture is considered to be of type 64
   (real and imag parts are of type float).
   Destination pictures will be of type 32 (float) and contain
   the real (Dst1Pic) and imag (Dst2Pic) parts if Mode==Real_Imag or
   the module (Dst1Pic) and phase (Dst2Pic) if Mode==Mod_Arg.
*/

  
int _32to64( char *Src1Pic, char *Src2Pic, char *ComplexPic, int Mode );
/* 
Transforming of real data to complex data:
   Src1Pic     - First destination picture file name;
   Src2Pic     - Second destination picture file name;
   ComplexPic  - Source picture file name;
   Mode        - Flag of transform method;
     Source pictures are considered to be of type 32 (float) and contain
   the real (Src1Pic) and imag (Src2Pic) parts if Mode==Real_Imag or
   the module (Src1Pic) and phase (Src2Pic) if Mode==Mod_Arg.
   Destination picture will be of type 64 (real and imag parts are 
   of type float).
*/

int _64to_mod( char *ComplexPic, char *DstPic );
/* 
Transforming of complex data to real data:
   ComplexPic  - Source picture file name;
   DstPic      - Destination picture file name;
     Source picture is considered to be of type 64
   (real and imag parts are of type float).
   Destination picture will be of type 32 (float) and contain
   the module.
*/

int _64to_ph( char *ComplexPic, char *DstPic );
/* 
Transforming of complex data to real data:
   ComplexPic  - Source picture file name;
   DstPic      - Destination picture file name;
     Source picture is considered to be of type 64
   (real and imag parts are of type float).
   Destination picture will be of type 32 (float) and contain
   the phase.
*/

int _64to_mph( char *ComplexPic, char *DstPic, int Mode );

#endif
